package com.zhsj.OkeHomeConsumption.ui.activity.bussiness.mvp;

import android.content.Context;

import com.hjq.base.BaseDialog;
import com.zhsj.OkeHomeConsumption.common.Constants;
import com.zhsj.OkeHomeConsumption.common.OkeHomeConsumptionApi;
import com.zhsj.OkeHomeConsumption.network.HttpClient;
import com.zhsj.OkeHomeConsumption.network.JsonResponseHandler;
import com.zhsj.OkeHomeConsumption.other.TimeChecker;
import com.zhsj.OkeHomeConsumption.other.TimeOutHandler;
import com.zhsj.OkeHomeConsumption.other.URLEntity;
import com.zhsj.OkeHomeConsumption.utils.SignUtil;

import java.util.HashMap;

/**
 * * <p>文件描述：商家收款二维码逻辑层<p>
 */
public class ReceiptQRcodePresenter {
    public ReceiptQRcodeUIInterFace mUIInterFace;
    private BaseDialog pDialogUtils = null;
    public TimeChecker timeChecker;

    public ReceiptQRcodePresenter(Context mContext, ReceiptQRcodeUIInterFace uiInterface) {
        mUIInterFace = uiInterface;
        pDialogUtils = new BaseDialog(mContext);
        timeChecker = new TimeChecker(TimeOutHandler.timeOutHandler, Constants.TIME_OUT);
    }


    /**
     * 商家收款二维码
     *
     * @param
     */
    public void IncomeGet( int userId) {
        HashMap<String, String> paramMaps = new HashMap<String, String>();
        final HashMap<String, String> mLogOnHashMap = new HashMap<String, String>();
        mLogOnHashMap.put("v", Constants.APPVERSION);
        mLogOnHashMap.put("t", Constants.TIME);
        mLogOnHashMap.put("deviceToken", Constants.DEVICETOKEN);
        mLogOnHashMap.put("client", Constants.CLIENT);
        mLogOnHashMap.put("deviceId", URLEntity.getInstance().getImei());
        mLogOnHashMap.put("platform", Constants.PLAFORM);


        paramMaps.put("userId",String.valueOf(userId));
        mLogOnHashMap.put("userId", String.valueOf(userId));


        // 网络计时器及线程
        TimeOutHandler.pDialogUtils = pDialogUtils;
        pDialogUtils.show();
        timeChecker.start();
        // 获取sign签名
        Constants.SIGN = SignUtil.getInstance().getSign(mLogOnHashMap);
        HttpClient.get(OkeHomeConsumptionApi.MONEY_QRCODE, paramMaps, new JsonResponseHandler() {
            @Override
            public void onSuccess(int statusCode, String content) {
                super.onSuccess(statusCode, content);
                timeChecker.check();
                pDialogUtils.dismiss();
                TimeOutHandler.pDialogUtils = null;
                mUIInterFace.IncomeGet(content);
            }

            @Override
            public void onFailure(Throwable e) {
                super.onFailure(e);
                timeChecker.check();
                pDialogUtils.dismiss();
                TimeOutHandler.pDialogUtils = null;
            }
        });
    }

}
